#ifndef _DriverDCDC_H_
#define _DriverDCDC_H_


/* 定时器输出PWM通道 */
#define DCDC_BUCK_TIMER             TIMER1
#define DCDC_BOOST_TIMER            TIMER1
#define DCDC_BUCK_B_TIMER           TIMER2
#define DCDC_BOOST_B_TIMER          TIMER2

/* 此宏定义要等于定时器 pulse */
#define DCDC_PULSE_MAX              (64000000 / 20000 - 1)


/* 电压环 */
#define PID_VOLTAGE_P               6000
#define PID_VOLTAGE_I               100
#define PID_VOLTAGE_D               2000

/* 误差积分上限 */
#define PID_VOLTAGE_EMAX            50000

/* 积分的上下限 */
#define PID_VOLTAGE_IMAX            PID_VOLTAGE_OMAX
#define PID_VOLTAGE_IMIN            PID_VOLTAGE_OMIN

/* 输出的上下限 */
#define PID_VOLTAGE_OMAX            10000
#define PID_VOLTAGE_OMIN            -10


/* 电流环 */
#define PID_CURRENT_P               200
#define PID_CURRENT_I               30
#define PID_CURRENT_D               1

/* 误差积分上限 */
#define PID_CURRENT_EMAX            (PID_VOLTAGE_OMAX + 1)

/* 积分的上下限 */
#define PID_CURRENT_IMAX            PID_CURRENT_OMAX
#define PID_CURRENT_IMAX            PID_CURRENT_OMAX
#define PID_CURRENT_IMIN            PID_CURRENT_OMIN

/* 输出的上下限 */
#define PID_CURRENT_OMAX            ((DCDC_PULSE_MAX * 2) * 1000)
#define PID_CURRENT_OMIN            0



/* DC输出 */
typedef struct
{
    int32_t currentInductive;       /* 电感电流：mA */
    int32_t currentInductiveB;      /* 电感电流：mA */
    int32_t voltageOut;             /* 输出电压：mV */
    int32_t currentOut;             /* 输出电流：mA */
    int32_t powerOut;               /* 输出功率：mW */
    int32_t temperature;            /* 温度：m摄氏度 */

    int32_t voltageOutFilter;       /* 滤波输出电压：V */
    int32_t currentOutFilter;       /* 滤波输出电流：A */
    int32_t powerOutFilter;         /* 滤波输出功率：W */

    int32_t currentInductiveSet;    /* 目标输入功率：mA */
    int32_t voltageOutSet;          /* 目标输出电压：mV */
    int32_t voltageOutSlowStart;    /* 目标输出电压（缓启动）：mV */

    int32_t voltageOutError;        /* 错误时电压值：mV */
    int32_t currentOutError;        /* 错误时电流值：mA */
    int32_t temperatureError;       /* 错误时温度值：摄氏度 */

    uint8_t switchs;                /* 开关 */
} DCDCPortType;


void vDCDCxInit(void);
int8_t cDCDCxOpen(void);
int8_t cDCDCxClose(void);
int8_t cDCDCxVoltageSet(int32_t iValue);
int8_t cDCDCxControl(void);
int8_t cDCDCxInfoUpdate(void);
DCDCPortType *ptypeDCDCxInfoGet(void);


#endif
